package org.ediba.siri.web.rest;

import java.util.LinkedList;
import java.util.List;

import org.springframework.util.StringUtils;

public class StringArrayPropertyEditor extends
		org.springframework.beans.propertyeditors.StringArrayPropertyEditor {

	private final boolean ignoreEmptyValues;

	public StringArrayPropertyEditor(String separator, String charsToDelete, boolean emptyArrayAsNull, boolean trimValues, boolean ignoreEmptyValues) {
		super(separator, charsToDelete, emptyArrayAsNull, trimValues);
		this.ignoreEmptyValues = ignoreEmptyValues; 
	}
	
	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		super.setAsText(text);
		if (this.ignoreEmptyValues){
			List<String> list = new LinkedList<String>();
			for (String string : (String[])this.getValue())
				if (StringUtils.hasText(string))
					list.add(string);
			this.setValue(StringUtils.toStringArray(list));
		}
	}
	
}
